package Objects;

import java.util.ArrayList;

public class Neighbors {
	ArrayList<Config> myNeighbors = new ArrayList<Config>();
	
	public ArrayList<Config> getMyNeighbors(){
		return myNeighbors;
	}
	
	public void setMyNeighbors(ArrayList<Config> neighbors){
		myNeighbors = neighbors;
	}
	
	public void addNeighbor(Config neighbor){
		myNeighbors.add(neighbor);
	}
	
	public void addNeighbor(String name, String ip){
		for(int i = 0; i < myNeighbors.size(); i++){
			if(myNeighbors.get(i).getRouterID().equals(name)){
				myNeighbors.get(i).setIP(ip);
			}
		}
	}
	
	public void removeNeighbor(String neighborID){
		for(int i = 0; i < myNeighbors.size(); i++){
			if(myNeighbors.get(i).getRouterID().equals(neighborID)){
				myNeighbors.get(i).setIP(null);
			}
		}
	}
	
	public ArrayList<String> getAllNeighborIPs(){
		ArrayList<String> ips = new ArrayList<String>();
		for(int i = 0; i < myNeighbors.size(); i++){
			ips.add(myNeighbors.get(i).getIP());
		}
		return ips;
	}
	
	public ArrayList<String> getIntraNeighborIPs(){
		ArrayList<String> ips = new ArrayList<String>();
		for(int i = 0; i < myNeighbors.size(); i++){
			if(myNeighbors.get(i).getIG() == 'i'){
				ips.add(myNeighbors.get(i).getIP());
			}
		}
		return ips;
	}
	
	public ArrayList<String> getInterNeighborIPs(){
		ArrayList<String> ips = new ArrayList<String>();
		for(int i = 0; i < myNeighbors.size(); i++){
			if(myNeighbors.get(i).getIG() == 'g'){
				ips.add(myNeighbors.get(i).getIP());
			}
		}
		return ips;
	}
	
	public Config getNeighborByID(String routerID){
		Config neighbor = null;
		for(int i = 0; i < myNeighbors.size(); i++){
			if(myNeighbors.get(i).getRouterID().equals(routerID)){
				neighbor = myNeighbors.get(i);
			}
		}
		return neighbor;
	}
	
	public String printList(){
		String toPrint = "";
		for(int i = 0; i < myNeighbors.size(); i++){
			toPrint += myNeighbors.get(i).getRouterID()+", ";
		}
		toPrint = toPrint.substring(0, toPrint.length()-2);
		return toPrint;
	}

	@Override
	public String toString() {
		return "Neighbors [myNeighbors=" + myNeighbors + "]";
	}	
}